package com.huanbao.oil.app.activity;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.LinearInterpolator;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.google.gson.Gson;
import com.huanbao.oil.app.R;
import com.huanbao.oil.app.application.MessageEvent;
import com.huanbao.oil.app.application.UserEvent;
import com.huanbao.oil.app.commons.Arithmetic4Double;
import com.huanbao.oil.app.commons.JsonUtil;
import com.huanbao.oil.app.commons.UtilsLog;
import com.huanbao.oil.app.model.MainModel;
import com.huanbao.oil.app.model.StartOrEndModel;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;

@SuppressWarnings("MagicConstant")
public class HomeFragment extends Fragment {
    public static final String BUNDLE_TITLE = "title";
    @BindView(R.id.home_fragment_im_fengshan_1)
    ImageView homeFragmentImFengshan1;
    @BindView(R.id.home_fragment_im_fengshan_2)
    ImageView homeFragmentImFengshan2;
    @BindView(R.id.home_fragment_im_fengshan_3)
    ImageView homeFragmentImFengshan3;
    @BindView(R.id.home_fragment_im_fengshan_4)
    ImageView homeFragmentImFengshan4;
    @BindView(R.id.home_fragment_im_fengshan_5)
    ImageView homeFragmentImFengshan5;
    @BindView(R.id.home_fragment_im_fengshan_6)
    ImageView homeFragmentImFengshan6;
    @BindView(R.id.home_fragment_im_arrow01)
    ImageView homeFragmentImArrow01;
    @BindView(R.id.home_fragment_im_arrow02)
    ImageView homeFragmentImArrow02;
    Unbinder unbinder;
    @BindView(R.id.home_fragment_btn_start)
    Button homeFragmentBtnStart;
    @BindView(R.id.home_fragment_btn_end)
    Button homeFragmentBtnEnd;
    @BindView(R.id.home_fragment_tv_1)
    TextView homeFragmentTv1;//右侧看似输入框第一个，一下以此类推
    @BindView(R.id.home_fragment_tv_2)
    TextView homeFragmentTv2;//第二个
    @BindView(R.id.home_fragment_tv_3)
    TextView homeFragmentTv3;//。。。
    @BindView(R.id.home_fragment_tv_4)
    TextView homeFragmentTv4;//。。。
    @BindView(R.id.home_fragment_tv_5)
    TextView homeFragmentTv5;//。。。
    @BindView(R.id.home_fragment_tv_6)
    TextView homeFragmentTv6;//。。。
    @BindView(R.id.home_fragment_tv_7)
    TextView homeFragmentTv7;//第七个
    @BindView(R.id.home_fragment_im_a1)
    ImageView homeFragmentImA1;
    @BindView(R.id.home_fragment_im_a2)
    ImageView homeFragmentImA2;
    @BindView(R.id.home_fragment_im_b1)
    ImageView homeFragmentImB1;
    @BindView(R.id.home_fragment_im_b2)
    ImageView homeFragmentImB2;
    @BindView(R.id.home_fragment_im_c1)
    ImageView homeFragmentImC1;
    @BindView(R.id.home_fragment_im_c2)
    ImageView homeFragmentImC2;
    @BindView(R.id.home_fragment_zhenkongbeng)
    ImageView homeFragmentZhenkongbeng;
    @BindView(R.id.home_fragment_fengji)
    ImageView homeFragmentFengji;
    @BindView(R.id.home_fragment_youbeng)
    ImageView homeFragmentYoubeng;
    @BindView(R.id.home_fragment_yasuoji21)
    ImageView homeFragmentYasuoji21;
    @BindView(R.id.home_fragment_yasuoji22)
    ImageView homeFragmentYasuoji22;
    @BindView(R.id.home_fragment_zhenkongbeng2)
    ImageView homeFragmentZhenkongbeng2;
    @BindView(R.id.home_fragment_fengji2)
    ImageView homeFragmentFengji2;
    @BindView(R.id.home_fragment_youbeng2)
    ImageView homeFragmentYoubeng2;
    @BindView(R.id.home_fragment_yasuoji212)
    ImageView homeFragmentYasuoji212;
    @BindView(R.id.home_fragment_yasuoji222)
    ImageView homeFragmentYasuoji222;

    private String mTitle = "DefaultValue";
    private MainActivity mainActivity;
    private View view;
    private static int FENG_SHAN_TIME = 2000;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mainActivity = (MainActivity) getActivity();
        EventBus.getDefault().register(this);
        Bundle arguments = getArguments();
        if (arguments != null) {
            mTitle = arguments.getString(BUNDLE_TITLE);
        }
        view = inflater.inflate(R.layout.home_fragment, container, false);
        unbinder = ButterKnife.bind(this, view);
        homeFragmentBtnStart.setBackgroundResource(R.drawable.my_shape);
        homeFragmentBtnEnd.setBackgroundResource(R.drawable.my_shape_blue);
//        homeFragmentZhenkongbeng.setBackgroundResource(R.drawable.zhengkongbeng2);
//        homeFragmentFengji.setBackgroundResource(R.drawable.fengji2);
//        homeFragmentYoubeng.setBackgroundResource(R.drawable.shangye2);
//        homeFragmentYasuoji21.setBackgroundResource(R.drawable.yasuoji21_2);
//        homeFragmentYasuoji22.setBackgroundResource(R.drawable.yasuoji22_2);
        homeFragmentZhenkongbeng2.setVisibility(View.GONE);
        homeFragmentFengji2.setVisibility(View.GONE);
        homeFragmentYoubeng2.setVisibility(View.GONE);
        homeFragmentYasuoji212.setVisibility(View.GONE);
        homeFragmentYasuoji222.setVisibility(View.GONE);
        return view;
    }

    @Override
    public void onResume() {
        super.onResume();
        if (mainActivity.IsStart) {
            //系统开始
        } else {
            //系统结束
        }
        mainActivity.setSocketData(3);
    }

    private void initViewImages() {
//闪烁
        AlphaAnimation alphaAnimation1 = new AlphaAnimation(0.1f, 1.0f);
        alphaAnimation1.setDuration(3000);
        alphaAnimation1.setRepeatCount(Animation.INFINITE);
        alphaAnimation1.setRepeatMode(Animation.RESTART);
        homeFragmentImArrow01.setAnimation(alphaAnimation1);
        alphaAnimation1.start();
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
        EventBus.getDefault().unregister(this);
    }

    ObjectAnimator animator_1 = null;
    boolean Is_animator_1 = true;

    private void setAnimator1() {
        animator_1 = ObjectAnimator.ofFloat(homeFragmentImFengshan1, "rotation", 0f, 360f);
        LinearInterpolator lin = new LinearInterpolator();
        animator_1.setInterpolator(lin);
        animator_1.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (Is_animator_1) {
                    setAnimator1();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator_1.setDuration(FENG_SHAN_TIME);
        animator_1.start();
    }

    ObjectAnimator animator_2 = null;
    boolean Is_animator_2 = true;

    private void setAnimator2() {
        animator_2 = ObjectAnimator.ofFloat(homeFragmentImFengshan2, "rotation", 0f, 360f);
        LinearInterpolator lin = new LinearInterpolator();
        animator_2.setInterpolator(lin);
        animator_2.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (Is_animator_2) {
                    setAnimator2();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator_2.setDuration(FENG_SHAN_TIME);
        animator_2.start();
    }

    ObjectAnimator animator_3 = null;
    boolean Is_animator_3 = true;

    private void setAnimator3() {
        animator_3 = ObjectAnimator.ofFloat(homeFragmentImFengshan3, "rotation", 0f, 360f);
        LinearInterpolator lin = new LinearInterpolator();
        animator_3.setInterpolator(lin);
        animator_3.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (Is_animator_3) {
                    setAnimator3();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator_3.setDuration(FENG_SHAN_TIME);
        animator_3.start();
    }

    ObjectAnimator animator_4 = null;
    boolean Is_animator_4 = true;

    private void setAnimator4() {
        animator_4 = ObjectAnimator.ofFloat(homeFragmentImFengshan4, "rotation", 0f, 360f);
        LinearInterpolator lin = new LinearInterpolator();
        animator_4.setInterpolator(lin);
        animator_4.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (Is_animator_4) {
                    setAnimator4();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator_4.setDuration(FENG_SHAN_TIME);
        animator_4.start();
    }

    ObjectAnimator animator_5 = null;
    boolean Is_animator_5 = true;

    private void setAnimator5() {
        animator_5 = ObjectAnimator.ofFloat(homeFragmentImFengshan5, "rotation", 0f, 360f);
        LinearInterpolator lin = new LinearInterpolator();
        animator_5.setInterpolator(lin);
        animator_5.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (Is_animator_5) {
                    setAnimator5();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator_5.setDuration(FENG_SHAN_TIME);
        animator_5.start();
    }

    ObjectAnimator animator_6 = null;
    boolean Is_animator_6 = true;

    private void setAnimator6() {
        animator_6 = ObjectAnimator.ofFloat(homeFragmentImFengshan6, "rotation", 0f, 360f);
        LinearInterpolator lin = new LinearInterpolator();
        animator_6.setInterpolator(lin);
        animator_6.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                if (Is_animator_6) {
                    setAnimator6();
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
        animator_6.setDuration(FENG_SHAN_TIME);
        animator_6.start();
    }

    void startAnimator() {
        Is_animator_1 = true;
        setAnimator1();
        Is_animator_2 = true;
        setAnimator2();
        Is_animator_3 = true;
        setAnimator3();
        Is_animator_4 = true;
        setAnimator4();
        Is_animator_5 = true;
        setAnimator5();
        Is_animator_6 = true;
        setAnimator6();
    }

    void stopAnimator() {
        if (animator_1 != null) {
            Is_animator_1 = false;
        }
        if (animator_2 != null) {
            Is_animator_2 = false;
        }
        if (animator_3 != null) {
            Is_animator_3 = false;
        }
        if (animator_4 != null) {
            Is_animator_4 = false;
        }
        if (animator_5 != null) {
            Is_animator_5 = false;
        }
        if (animator_6 != null) {
            Is_animator_6 = false;
        }
    }

    @OnClick({R.id.home_fragment_btn_start, R.id.home_fragment_btn_end, R.id.home_fragment_tv_6})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.home_fragment_tv_6:
                //工程师
                if (mainActivity.IsLogin == false) {
                    mainActivity.showDialog();
                }
                break;
            case R.id.home_fragment_btn_start:
                if (mainActivity.IsLogin) {
                    showTwo(1, "系统开始");
//                    startOrEnd(1);
                } else {
                    mainActivity.showDialog();
                }

                break;
            case R.id.home_fragment_btn_end:
                if (mainActivity.IsLogin) {
                    showTwo(2, "系统停止");
//                    startOrEnd(0);
                } else {
                    mainActivity.showDialog();
                }

                break;
        }
    }

    private Handler mHandler;
    private Runnable runnable;
    private int FLAG = 0;

    /**
     * 两个按钮的 dialog
     */
    private AlertDialog.Builder builder;

    private void showTwo(final int flag, String msg) {
        builder = new AlertDialog.Builder(mainActivity).setIcon(R.mipmap.ic_launcher).setTitle("提示")
                .setMessage(msg).setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情
//                        Toast.makeText(mainActivity, "确定按钮", Toast.LENGTH_LONG).show();
                        if (flag == 1) {
//                            startHandler();
                            startOrEnd(1);//系统启动
                            startnew();
                        } else {
                            startOrEnd(0);//系统停止
                            stopHandler();
                        }
                    }
                }).setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {
                        //ToDo: 你想做的事情
//                        Toast.makeText(mainActivity, "关闭按钮", Toast.LENGTH_LONG).show();
                        dialogInterface.dismiss();
                    }
                });
        builder.create().show();
    }

    void startOrEnd(int start_stop) {
        //1表示启动，0表示停止
        StartOrEndModel model = new StartOrEndModel();
        model.setCmd_type(1);
        model.setStart_stop(start_stop);
        Gson gson = new Gson();
        mainActivity.jsonStr = gson.toJson(model);
        mainActivity.openDoor(mainActivity.jsonStr);
    }

    void stopHandler() {
        stopAnimator();
        homeFragmentBtnStart.setBackgroundResource(R.drawable.my_shape);
        homeFragmentBtnEnd.setBackgroundResource(R.drawable.my_shape_blue);
        if (mHandler != null) {
            mHandler.removeCallbacks(runnable);
            mHandler = null;
        }
        if (mHandler_a1 != null) {
            mHandler_a1.removeCallbacks(runnable_a1);
            mHandler_a1 = null;
        }
        if (mHandler_b1 != null) {
            mHandler_b1.removeCallbacks(runnable_b1);
            mHandler_b1 = null;
        }
        if (mHandler_c1 != null) {
            mHandler_c1.removeCallbacks(runnable_c1);
            mHandler_c1 = null;
        }
        if (mHandler_new != null) {
            mHandler_new.removeCallbacks(runnable_new);
            mHandler_new = null;
        }
    }

    void startHandler() {
        startAnimator();
        homeFragmentBtnStart.setBackgroundResource(R.drawable.my_shape_blue);
        homeFragmentBtnEnd.setBackgroundResource(R.drawable.my_shape);

        startA1();
        startB1();
        startC1();
    }

    private Handler mHandler_new;
    private Runnable runnable_new;

    void startnew() {
        if (mHandler_new != null) {
            return;
        }
//        Looper.prepare();
        mHandler_new = new Handler();
        //相当于定时器，每隔2s执行一次该线程
        runnable_new = new Runnable() {
            @Override
            public void run() {
                if (FLAG == 0) {
                    homeFragmentZhenkongbeng.setVisibility(View.VISIBLE);
                    homeFragmentFengji.setVisibility(View.VISIBLE);
                    homeFragmentYoubeng.setVisibility(View.VISIBLE);
                    homeFragmentYasuoji21.setVisibility(View.VISIBLE);
                    homeFragmentYasuoji22.setVisibility(View.VISIBLE);
                    homeFragmentZhenkongbeng2.setVisibility(View.GONE);
                    homeFragmentFengji2.setVisibility(View.GONE);
                    homeFragmentYoubeng2.setVisibility(View.GONE);
                    homeFragmentYasuoji212.setVisibility(View.GONE);
                    homeFragmentYasuoji222.setVisibility(View.GONE);
                    FLAG = 1;
                } else {
                    homeFragmentZhenkongbeng.setVisibility(View.GONE);
                    homeFragmentFengji.setVisibility(View.GONE);
                    homeFragmentYoubeng.setVisibility(View.GONE);
                    homeFragmentYasuoji21.setVisibility(View.GONE);
                    homeFragmentYasuoji22.setVisibility(View.GONE);

                    homeFragmentZhenkongbeng2.setVisibility(View.VISIBLE);
                    homeFragmentFengji2.setVisibility(View.VISIBLE);

                    homeFragmentYoubeng2.setVisibility(View.VISIBLE);
                    homeFragmentYasuoji212.setVisibility(View.VISIBLE);
                    homeFragmentYasuoji222.setVisibility(View.VISIBLE);
                    FLAG = 0;
                }
                mHandler_new.postDelayed(this, 1000);                             //相当于定时器，每隔2s执行一次该线程
            }
        };
//        Looper.loop();
        mHandler_new.post(runnable_new);
    }

    private Handler mHandler_a1;
    private Runnable runnable_a1;


    void startA1() {
        if (mHandler_a1 != null) {
            return;
        }
        mHandler_a1 = new Handler();
        //相当于定时器，每隔2s执行一次该线程
        runnable_a1 = new Runnable() {
            @Override
            public void run() {
                if (FLAG == 0) {
                    homeFragmentImA1.setVisibility(View.VISIBLE);
                    homeFragmentImA2.setVisibility(View.GONE);
                    FLAG = 1;
                } else {
                    homeFragmentImA1.setVisibility(View.GONE);
                    homeFragmentImA2.setVisibility(View.VISIBLE);
                    FLAG = 0;
                }
                mHandler_a1.postDelayed(this, 1000);                             //相当于定时器，每隔2s执行一次该线程
            }
        };
        mHandler_a1.post(runnable_a1);
    }

    private Handler mHandler_b1;
    private Runnable runnable_b1;

    void startB1() {
        if (mHandler_b1 != null) {
            return;
        }
        mHandler_b1 = new Handler();
        //相当于定时器，每隔2s执行一次该线程
        runnable_b1 = new Runnable() {
            @Override
            public void run() {
                if (FLAG == 0) {
                    homeFragmentImB1.setVisibility(View.VISIBLE);
                    homeFragmentImB2.setVisibility(View.GONE);
                    FLAG = 1;
                } else {
                    homeFragmentImB1.setVisibility(View.GONE);
                    homeFragmentImB2.setVisibility(View.VISIBLE);
                    FLAG = 0;
                }
                mHandler_b1.postDelayed(this, 1000);                             //相当于定时器，每隔2s执行一次该线程
            }
        };
        mHandler_b1.post(runnable_b1);
    }

    private Handler mHandler_c1;
    private Runnable runnable_c1;

    void startC1() {
        if (mHandler_c1 != null) {
            return;
        }
        mHandler_c1 = new Handler();
        //相当于定时器，每隔2s执行一次该线程
        runnable_c1 = new Runnable() {
            @Override
            public void run() {
                if (FLAG == 0) {
                    homeFragmentImC1.setVisibility(View.VISIBLE);
                    homeFragmentImC2.setVisibility(View.GONE);
                    FLAG = 1;
                } else {
                    homeFragmentImC1.setVisibility(View.GONE);
                    homeFragmentImC2.setVisibility(View.VISIBLE);
                    FLAG = 0;
                }
                mHandler_c1.postDelayed(this, 1000);                             //相当于定时器，每隔2s执行一次该线程
            }
        };
        mHandler_c1.post(runnable_c1);
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onUserEvent(UserEvent event) {
        UtilsLog.e("HomeFragment==onUserEvent::" + event.getMessage());
        homeFragmentTv6.setText(event.getMessage());
    }

    public void setName(String name) {
        homeFragmentTv6.setText(name);
    }

    List<MainModel> modelList = new ArrayList<>();

    @Subscribe(threadMode = ThreadMode.ASYNC, sticky = true)
    public void onMessageEvent(MessageEvent event) {
        if (mainActivity.TCP_MODE == 0) {
            if (!TextUtils.isEmpty(event.getMessage()) && !"{}".equals(event.getMessage())
                    && !"{[]}".equals(event.getMessage())) {
                try {
                    JSONObject jsonObject = new JSONObject(event.getMessage());
                    int cmd_type = 0;
                    if (jsonObject.has("cmd_type")) {
                        cmd_type = jsonObject.getInt("cmd_type");
                        UtilsLog.e("HomeFragmentcmd_type==" + cmd_type);
                    }
                    if (cmd_type == 2222) {
//                        UtilsLog.e("HomeFragment进入解析==");
                        if (jsonObject.getString("pnts") != "[]" && !TextUtils.isEmpty(jsonObject.getString("pnts"))) {
                            modelList = JsonUtil.stringToArray(jsonObject.getString("pnts"), MainModel[].class);
                            if (modelList != null && modelList.size() > 0) {
//                                UtilsLog.e("HomeFragmentpnts==");
                                new Thread(new Runnable() {
                                    @Override
                                    public void run() {
//                                        UtilsLog.e("HomeFragmenthandler==");
                                        Message msg = new Message();
                                        msg.obj = modelList;
                                        msg.arg1 = 1;
                                        handler_homeFragment.sendMessage(msg);
                                    }
                                }).start();
                            } else {
                                UtilsLog.e("HomeFragment零条数据==");
                            }
                        }
                    } else if (cmd_type == 2) {
                        int result = 0;
                        if (jsonObject.has("result")) {
                            result = jsonObject.getInt("result");
                            UtilsLog.e("HomeFragment===result==" + result);
                            if (result == 1) {
//                            startHandler();//开启动画，风扇，水流
                                startnew();
                            } else if (result == 0) {
                                stopHandler();//关闭动画，风扇，水流
                            }
                        }

                    } else if (cmd_type == 4) {
//                        UtilsLog.e("HomeFragment进入解析==");
                        if (jsonObject.getString("pnts") != "[]" && !TextUtils.isEmpty(jsonObject.getString("pnts"))) {
                            modelList = JsonUtil.stringToArray(jsonObject.getString("pnts"), MainModel[].class);
                            if (modelList != null && modelList.size() > 0) {
//                                UtilsLog.e("HomeFragmentpnts==");
                                new Thread(new Runnable() {
                                    @Override
                                    public void run() {
//                                        UtilsLog.e("HomeFragmenthandler==");
                                        Message msg = new Message();
                                        msg.obj = modelList;
                                        msg.arg1 = 1;
                                        handler_homeFragment.sendMessage(msg);
                                    }
                                }).start();
                            } else {
                                UtilsLog.e("HomeFragment零条数据==");
                            }
                        }
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                    UtilsLog.e("HomeFragment进入解析异常==" + e.getMessage());
                }
            }
        }
    }

    private Handler handler_homeFragment = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (msg.obj != null) {
                List<MainModel> lList = (List<MainModel>) msg.obj;
                for (int i = 0; i < lList.size(); i++) {
                    HashMap<String, String> map = mainActivity.getDataHashMap();
                    if (!TextUtils.isEmpty(map.get(String.valueOf(lList.get(i).getPnt_id())))) {
                        map.put(String.valueOf(lList.get(i).getPnt_id()), String.valueOf(lList.get(i).getValue()));
                    } else {
                        UtilsLog.e("HomeFragmentHashMap==数据为空");
                    }
                }
//                Set<String> set = dataHashMap.keySet();
//                for (String string : set) {
//                    UtilsLog.e("====="+string + " " + dataHashMap.get(string));
//                }
            } else {
//                UtilsLog.e("HomeFragment22222222222==");
            }
            switch (msg.arg1) {
                case 1:
                    //更新UI右侧数据信息

                    homeFragmentTv1.setText(Arithmetic4Double.keepOne(Double.parseDouble(mainActivity.getDataHashMap().get("3"))) + "℃");
                    homeFragmentTv2.setText(Arithmetic4Double.keepOne(Double.parseDouble(mainActivity.getDataHashMap().get("4"))) + "℃");
                    homeFragmentTv3.setText(Arithmetic4Double.keepOne(Double.parseDouble(mainActivity.getDataHashMap().get("5"))) + "℃");
                    homeFragmentTv4.setText(Arithmetic4Double.keepOne(Double.parseDouble(mainActivity.getDataHashMap().get("1"))) + "Pa");
                    homeFragmentTv5.setText(Arithmetic4Double.keepOne(Double.parseDouble(mainActivity.getDataHashMap().get("2"))) + "m");
//                    homeFragmentTv6.setText(mainActivity.dataHashMap.get(1));
//                    homeFragmentTv7.setText(Arithmetic4Double.keepOne(Double.parseDouble(mainActivity.getDataHashMap().get("1000"))) + "min");
                    break;
            }
        }
    };

}
